package com.project.dao.impl;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

@Repository
public class UserDaoImpl extends BaseDao implements IUserDao {
    @Override
    public UserBean login(String userName, String pwd) {
        UserBean user = null;
        this.setConnection();
        try {
            ps = con.prepareStatement("select * from t_user where u_name=? and u_pwd=? ");
            ps.setObject(1, userName);
            ps.setObject(2, pwd);

            rs = ps.executeQuery();
            if (rs.next()) {
                user=new UserBean();
                user.setId(rs.getInt("pk_userId"));
                user.setUserName(rs.getString("u_name"));
                user.setPwd(rs.getString("u_pwd"));
                user.setNickName(rs.getString("u_nickName"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            this.closeConnection();
        }

        return user;
    }
}
